package ReflectionLearn.RefleDeepLearn;

import ReflectionLearn.RefleDeepLearnClass.Person;
import org.junit.jupiter.api.Test;


import java.lang.annotation.Annotation;

/**
 * @author Lenl
 * @version v1.0
 * @create 2021-06-07 20:26
 * @description 获取运行时类的接口、所在包、注解
 *
 */
public class InterfaceTest {

    /**
     * 获取运行时类的接口
     */
    @Test
    public void test(){
        Class clazz= Person.class;

        Class[] interfaces=clazz.getInterfaces();
        for(Class c:interfaces){
            System.out.println(c);
        }
        System.out.println("**********");
        //获取父类的接口
        Class[] interfaces1=clazz.getSuperclass().getInterfaces();
        for(Class c:interfaces1){
            System.out.println(c);
        }
    }

    /**
     * 获取运行时类所在的包
     */
    @Test
    public void test1(){
        Class clazz=Person.class;

        Package apackage=clazz.getPackage();
        System.out.println(apackage);
    }

    /**
     * 获取运行时类声明的注解
     */
    @Test
    public void test2(){
        Class clazz=Person.class;
        Annotation[] annos=clazz.getAnnotations();
        for (Annotation a:annos){
            System.out.println(a);
        }

    }


}
